$OpenBSD: patch-setup_py,v 1.12 2016/07/03 20:10:33 rpointel Exp $
--- setup.py.orig	Sat Jun 25 23:49:32 2016
+++ setup.py	Fri Jul  1 10:35:01 2016
@@ -35,6 +35,11 @@ COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig
 # This global variable is used to hold the list of modules to be disabled.
 disabled_module_list = []
 
+def usrlocal(p):
+    return os.path.join(os.environ['LOCALBASE'], p)
+def usrx11r6(p):
+    return os.path.join(os.environ['X11BASE'], p)
+
 def add_dir_to_list(dirlist, dir):
     """Add the directory 'dir' to the list 'dirlist' (at the front) if
     1) 'dir' is not already in 'dirlist'
@@ -456,8 +461,8 @@ class PyBuildExt(build_ext):
     def detect_modules(self):
         # Ensure that /usr/local is always used
         if not cross_compiling:
-            add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
-            add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
+            add_dir_to_list(self.compiler.library_dirs, usrlocal('lib'))
+            add_dir_to_list(self.compiler.include_dirs, usrlocal('include'))
         if cross_compiling:
             self.add_gcc_paths()
         self.add_multiarch_paths()
@@ -786,6 +791,8 @@ class PyBuildExt(build_ext):
                                                      'termcap'):
                 readline_libs.append('termcap')
             exts.append( Extension('readline', ['readline.c'],
+                                   extra_compile_args=['-nostdinc'],
+                                   include_dirs=['/usr/include'],
                                    library_dirs=['/usr/lib/termcap'],
                                    extra_link_args=readline_extra_link_args,
                                    libraries=readline_libs) )
@@ -922,7 +929,7 @@ class PyBuildExt(build_ext):
                 # BerkeleyDB 4.6.x is not stable on many architectures.
                 arch = platform_machine()
                 if arch not in ('i386', 'i486', 'i586', 'i686',
-                                'x86_64', 'ia64'):
+                                'x86_64', 'amd64', 'ia64'):
                     return False
             return True
 
@@ -992,6 +999,7 @@ class PyBuildExt(build_ext):
                 std_variants.append(os.path.join(dn, "db3.%d"%x))
 
         db_inc_paths = std_variants + db_inc_paths
+        db_inc_paths = [ usrlocal('include/db4') ]
         db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
 
         db_ver_inc_map = {}
@@ -1055,6 +1063,7 @@ class PyBuildExt(build_ext):
                     db_incdir.replace("include", 'lib64'),
                     db_incdir.replace("include", 'lib'),
                 ]
+                db_dirs_to_check = [usrlocal('lib/db4')]
 
                 if host_platform != 'darwin':
                     db_dirs_to_check = filter(os.path.isdir, db_dirs_to_check)
@@ -1077,6 +1086,7 @@ class PyBuildExt(build_ext):
                 # symlink to more general names?
                 for dblib in (('db-%d.%d' % db_ver),
                               ('db%d%d' % db_ver),
+                              ('db'),
                               ('db%d' % db_ver[0])):
                     dblib_file = self.compiler.find_library_file(
                                     db_dirs_to_check + lib_dirs, dblib )
@@ -1234,7 +1244,7 @@ class PyBuildExt(build_ext):
                 sysroot = macosx_sdk_root()
                 f = os.path.join(sysroot, f[1:])
 
-        if os.path.exists(f) and not db_incs:
+        if os.path.exists(f):
             data = open(f).read()
             m = re.search(r"#s*define\s+HASHVERSION\s+2\s*", data)
             if m is not None:
@@ -1840,7 +1850,7 @@ class PyBuildExt(build_ext):
         # For 8.4a2, the X11 headers are not included. Rather than include a
         # complicated search, this is a hard-coded path. It could bail out
         # if X11 libs are not found...
-        include_dirs.append('/usr/X11R6/include')
+        include_dirs.append(usrx11r6('include'))
         frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
 
         # All existing framework builds of Tcl/Tk don't support 64-bit
@@ -1895,8 +1905,7 @@ class PyBuildExt(build_ext):
         # The versions with dots are used on Unix, and the versions without
         # dots on Windows, for detection by cygwin.
         tcllib = tklib = tcl_includes = tk_includes = None
-        for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
-                        '8.2', '82', '8.1', '81', '8.0', '80']:
+        for version in ['85']:
             tklib = self.compiler.find_library_file(lib_dirs,
                                                         'tk' + version)
             tcllib = self.compiler.find_library_file(lib_dirs,
@@ -1939,17 +1948,9 @@ class PyBuildExt(build_ext):
         if host_platform == 'sunos5':
             include_dirs.append('/usr/openwin/include')
             added_lib_dirs.append('/usr/openwin/lib')
-        elif os.path.exists('/usr/X11R6/include'):
-            include_dirs.append('/usr/X11R6/include')
-            added_lib_dirs.append('/usr/X11R6/lib64')
-            added_lib_dirs.append('/usr/X11R6/lib')
-        elif os.path.exists('/usr/X11R5/include'):
-            include_dirs.append('/usr/X11R5/include')
-            added_lib_dirs.append('/usr/X11R5/lib')
-        else:
-            # Assume default location for X11
-            include_dirs.append('/usr/X11/include')
-            added_lib_dirs.append('/usr/X11/lib')
+        elif True:
+            include_dirs.append(usrx11r6('include'))
+            added_lib_dirs.append(usrx11r6('lib'))
 
         # If Cygwin, then verify that X is installed before proceeding
         if host_platform == 'cygwin':
